


from util.selenium.webdriver.common.by import By

from util.DataQuery.FormDataDecorator import FormDataDecorator


class WriteOptcond():
    # # # # # # # # # # # # # # #  这个数据需要从 ent_res_optcond 这个表中取。
    # # # # # # # # # # # # # # # category 为字典值，分别表示第一年，第二年和第三年。 value 分别为 1,2,3
    net_asset1_loc = (By.CSS_SELECTOR, 'input#netAsset1')
    sale_revenue1_loc = (By.CSS_SELECTOR, 'input#salesRevenue1')
    total_profit1_loc = (By.CSS_SELECTOR, 'input#totalProfit1')
    net_asset2_loc = (By.CSS_SELECTOR, 'input#netAsset2')
    sale_revenue2_loc = (By.CSS_SELECTOR, 'input#salesRevenue2')
    total_profit2_loc = (By.CSS_SELECTOR, 'input#totalProfit2')
    net_asset3_loc = (By.CSS_SELECTOR, 'input#netAsset3')
    sale_revenue3_loc = (By.CSS_SELECTOR, 'input#salesRevenue3')
    total_profit3_loc = (By.CSS_SELECTOR, 'input#totalProfit3')

    net_asset_map = {'3': net_asset1_loc, '2': net_asset2_loc, '1': net_asset3_loc}
    sale_revenue_map = {'3': sale_revenue1_loc, '2': sale_revenue2_loc, '1': sale_revenue3_loc}
    total_profit_map = {'3': total_profit1_loc, '2': total_profit2_loc, '1': total_profit3_loc}

    # 写代码时方便提示, 基本方法完成后删除
    # driver = driver

    def __init__(self, driver=None):
        self.driver = driver
    @property
    def class_name(self):
        return self.__class__.__name__

    def input_o(self, input_loc, driver=None, keys=''):
        keys = str(keys) if type(keys) == float else keys
        driver.find_element(*input_loc).clear()
        driver.find_element(*input_loc).send_keys(keys)

    @FormDataDecorator
    def write_optcond(self, category, net_assets, net_revenues, net_income):
        self.input_o(input_loc=self.net_asset_map.get(category), driver=self.driver, keys=net_assets)
        self.input_o(input_loc=self.sale_revenue_map.get(category), driver=self.driver, keys=net_revenues)
        self.input_o(input_loc=self.total_profit_map.get(category), driver=self.driver, keys=net_income)


# if __name__ == '__main__':
#     WriteOptcond.category = 1
#     print(WriteOptcond.net_asset_map.get(WriteOptcond.category))













